package com.txzt.gaea.config;

import org.beetl.core.ResourceLoader;
import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

/**
 * web 配置类
 *
 * @author Leo
 * @date 2016年11月12日 下午5:03:32
 */
@Configuration
public class BeetlConf {

    /**
     * beetl的配置
     */
    @Bean(initMethod = "init", name = "beetlConfig")
    public BeetlConfiguration getBeetlGroupUtilConfiguration() {
        BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
        ResourceLoader resourceLoader = new ClasspathResourceLoader(getClass().getClassLoader());
        beetlConfiguration.setResourceLoader(resourceLoader);
        beetlConfiguration.setConfigFileResource(new ClassPathResource("beetl.properties"));
        return beetlConfiguration;
    }

    /**
     * beetl的视图解析器
     */
    @Bean(name = "beetlViewResolver")
    public BeetlSpringViewResolver getBeetlSpringViewResolver(@Qualifier("beetlConfig") BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {
        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
        beetlSpringViewResolver.setOrder(0);
        beetlSpringViewResolver.setConfig(getBeetlGroupUtilConfiguration());
        return beetlSpringViewResolver;
    }

}
